var app = new Vue({
	el: '#app',
	data: {
		host: host,
		username: '',
		f3_tab: '',
		f2_tab: '',
		f1_tab: '',
		carts: '',
		data: '',
		url: '/list.html?cat=',
		sku_url: '/detail.html?sku=',
		cart_total_count: 0,
		image_url: host + '/media/',

	},
	mounted: function () {

	},

	methods: {
		// oa登录
		OA_login: function () {
			window.open('/OA_login.html',width=200,height=400)
			// var next = get_query_string('next') || '/';
			// axios.get(this.host + '/authoaurl/', {
			// 	responseType: 'json',
			// 	withCredentials: true,
			// }).then(function (resp) {
			// 	// var iWidth=500;                         //弹出窗口的宽度;
			// 	// var iHeight=570;                        //弹出窗口的高度;
			// 	// //window.screen.height获得屏幕的高，window.screen.width获得屏幕的宽
			// 	// var iTop = (window.screen.height-30-iHeight)/2;       //获得窗口的垂直位置;
			// 	// var iLeft = (window.screen.width-10-iWidth)/2;        //获得窗口的水平位置;
			// 	console.log(resp.data.login_url);
			// 	// window.location.href = resp.data.login_url;
			// 	window.open(resp.data.login_url,width=200,height=400)
			// }).catch(function () {
			// 	console.log('xxx');
			// })
		},
		logoutfunc: function () {
			axios.delete(this.host + '/logout/', {
				responseType: 'json',
				withCredentials: true,
			})
				.then(function (resp) {
					if (resp.data.code == 200) {
						location.href = 'index.html'
						return
					} else {
						alert('退出失败')
					}
				})
		},
		get_cart() {
			let url = this.host + '/carts/simple/';
			axios.get(url, {
				responseType: 'json',
				withCredentials: true,
			})
				.then(response => {
					this.carts = response.data.cart_skus;
					this.cart_total_count = 0;
					for (let i = 0; i < this.carts.length; i++) {
						if (this.carts[i].name.length > 25) {
							this.carts[i].name = this.carts[i].name.substring(0, 25) + '...';
						}
						this.cart_total_count += this.carts[i].count;
					}
				})
				.catch(error => {
					console.log(error);
				})
		},
		get_person_info: function () {
			var url = this.host + '/index/';
			axios.get(url, {
				responseType: 'json',
				withCredentials: true
			})
				.then(response => {
					if (response.data.code == 400) {

						return
					}

					this.data = response.data
				})
				.catch(error => {
					console.log('错误');

				})
		},

	},
	created() {
		let u_json = $cookies.get('username') //使用第三方库获取cookie
		let u_str = JSON.parse(u_json) //将数据进行json反序列化
		this.username = eval(u_str) //将unicode编码转为中文
		this.get_person_info()
		this.get_cart()
	}
})
